<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	
	/* generate registry
	 * @return Zend_Registry
	 */
	protected function _initRegistry(){
		$registry = Zend_Registry::getInstance();
		return $registry;
	}

	/**
	 * Register namespace Default_
	 * @return Zend_Application_Module_Autoloader
	 */
	protected function _initAutoload()
	{
		$moduleLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH));
		return $moduleLoader;

	}

	/**
	 *
	 * Enter description here ...
	 */
	protected function _initDoctype(){
		require_once 'Zend/Loader/Autoloader.php';
		$autoloader = Zend_Loader_Autoloader::getInstance();
		$autoloader->setFallbackAutoloader(true);
		$autoloader->registerNamespace('Validation_');

		Zend_Controller_Front::getInstance()->registerPlugin(new Application_Plugin_Ajax());
		/*
		 $controller->registerPlugin(new Application_Plugin_Acl());
		 try {
		 $controller->dispatch();
		 } catch (Exception $ex) {
		 die($ex->getMessage());
		 }
		 */
	}

	/**
	 * logowanie do pliku
	 */
	/*
	protected function _initLogger()
	{
		$writer = new Zend_Log_Writer_Stream('../logs/log.log');
		$logger = new Zend_Log($writer);
		Zend_Registry::set('logger', $logger);
	}
	*/
	
	/**
	 * Logowanie do bazy danych.
	 * 
	 * <p>
	 * W kodzie należy logować w ten spoób: <br />
	 * Zend_Registry::get('logger')->log('log emergency message', Zend_Log::EMERG); <br />
	 * Zend_Registry::get('logger')->info('just logging some information'); <br />
	 * </p>
	 * 
	 */
public function _initLogger(){

    $resource = $this->getPluginResource('db');
$dbAdapter = $resource->getDbAdapter();
    $columnMapping = array(
        'level' => 'priorityName',
        'priority' => 'priority',
        'message' => 'message',
        'created' => 'timestamp',
        'user_agent'=> 'user_agent',
        'get_vars' => 'get_vars',
        'post_vars' => 'post_vars',
        'ip' => 'ip'
    );

    $writerDb = new Zend_Log_Writer_Db($dbAdapter, 'logs', $columnMapping);
    $logger = new Zend_Log($writerDb);

    $logger->setEventItem('datetime',date('Y-m-d H:i:s'));
    $logger->setEventItem('user_agent',$_SERVER['HTTP_USER_AGENT']);
    $logger->setEventItem('get_vars',print_r($_GET,true));
    $logger->setEventItem('post_vars',print_r($_POST,true));
    $logger->setEventItem('ip',$_SERVER['REMOTE_ADDR']);

    Zend_Registry::set('logger', $logger);

}
    
	
	/**
     * Initialize Doctrine
     * @return Doctrine_Manager
     */
	/*
	public function _initDoctrine() {
        // include and register Doctrine's class loader
        require_once('Doctrine/Common/ClassLoader.php');
        $classLoader = new \Doctrine\Common\ClassLoader(
            'Doctrine', 
            APPLICATION_PATH . '/../library/'
        );
        $classLoader->register();
 
        // create the Doctrine configuration
        $config = new \Doctrine\ORM\Configuration();
 
        // setting the cache ( to ArrayCache. Take a look at
        // the Doctrine manual for different options ! )
        $cache = new \Doctrine\Common\Cache\ArrayCache;
        $config->setMetadataCacheImpl($cache);
        $config->setQueryCacheImpl($cache);
 
        // choosing the driver for our database schema
        // we'll use annotations
        $driver = $config->newDefaultAnnotationDriver(
            APPLICATION_PATH . '/models'
        );
        $config->setMetadataDriverImpl($driver);
 
        // set the proxy dir and set some options
        $config->setProxyDir(APPLICATION_PATH . '/models/Proxies');
        $config->setAutoGenerateProxyClasses(true);
        $config->setProxyNamespace('App\Proxies');
 
        // now create the entity manager and use the connection
        // settings we defined in our application.ini
        $connectionSettings = $this->getOption('doctrine');
        $conn = array(
            'driver'    => $connectionSettings['conn']['driv'],
            'user'      => $connectionSettings['conn']['user'],
            'password'  => $connectionSettings['conn']['pass'],
            'dbname'    => $connectionSettings['conn']['dbname'],
            'host'      => $connectionSettings['conn']['host']
        );
        $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
 
        // push the entity manager into our registry for later use
        $registry = Zend_Registry::getInstance();
        $registry->entitymanager = $entityManager;
 
        return $entityManager;
    }
    */
}

